Document cpu_weight config field and check value type.
<li>id: int, optional, default generated. Domain unique id.
<li>memory: int, required. Domain memory in MB.
<li>cpu: int, optional. Cpu to run on.
+ <li>cpu_weight, float, optional, default 1. Cpu weight - controls share of CPU.
<li>image: linux | netbsd | ..., required. Domain image (OS-specific element).
<li>backend: any backend device type, optional, default none.
<li>device: any device type, optional, repeats. Device.
self.config = None
self.id = None
self.dom = None
+ self.cpu_weight = 1
self.start_time = None
self.name = None
self.memory = None
try:
self.name = sxp.child_value(config, 'name')
self.check_name(self.name)
- self.cpu_weight = float(sxp.child_value(config, 'cpu_weight', '1'))
+ try:
+ self.cpu_weight = float(sxp.child_value(config, 'cpu_weight', '1'))
+ except:
+ raise VmError('invalid cpu weight')
if self.restore and self.dom:
xc.domain_setname(self.dom, self.name)
self.memory = int(sxp.child_value(config, 'memory'))
fn=set_value, default=128,
use="Domain memory in MB.")
-gopts.var('cpu_weight', val='CPU_WEIGHT',
- fn=set_value, default=1,
- use="CPU weight.")
+gopts.var('cpu_weight', val='WEIGHT',
+ fn=set_float, default=1,
+ use="""Set the new domain's cpu weight. WEIGHT is a float that controls the
+domain's share of the cpu.""")
gopts.var('console', val='PORT',
fn=set_int, default=None,
def set_value(opt, k, v):
- """Set an option to a valoue."""
+ """Set an option to a value."""
opt.set(v)
def set_int(opt, k, v):
opt.opts.err('Invalid value: ' + str(v))
opt.set(v)
+def set_float(opt, k, v):
+ """Set an option to a float value."""
+ try:
+ v = float(v)
+ except:
+ opt.opts.err('Invalid value: ' + str(v))
+ opt.set(v)
+
def append_value(opt, k, v):
"""Append a value to a list option."""
opt.append(v)